import {createStore} from 'redux'

const init_list = [
    {
        id:3,
        name: "张三",
        age: 18
    },
    {
        id:2,
        name: "李四",
        age: 18
    },
    {
        id:1,
        name: "王五",
        age: 18
    }
]

function personList(state = init_list,action){
    switch (action.type){
        case 'insert':
            const obj = action.data
            return [obj,...state]
        case 'delete':
            state.splice(action.index,1)
            return [...state]
        case 'update':
            var index = action.index
            state[index] = action.data
            return [...state]
        default:
            return state
    }
    
}

const store = createStore(personList) //创建一个store对象

export default store